# controlls the metadata associaated with each bug list. 

class BugListsController < ApplicationController
  layout 'admin_standard'
  before_filter :authenticate
  before_filter :get_project_context
  
  active_scaffold :bug_list
  active_scaffold :bug_list do |config|
      
      config.update.link.label = "View/Edit"
      config.actions.exclude :show
      #config.show.link.page = true
      config.list.per_page = 100
      #show.columns = [:display_name, :display_name_color, :description, :expert_query, :ownership_model, :use_projections, :use_ownership_change, :is_verification_list] 
      #config.show.link.action :show
      #config.show.type :record
      config.columns = [:display_name, :description, :expert_query, :ownership_model, :use_projections, :use_ownership_change, :is_verification_list]
      update.columns = [:display_name, :name, :display_name_color, :description, :expert_query, :ownership_model, :use_projections, :use_ownership_change, :is_verification_list] 
      config.columns[:ownership_model].form_ui = :select
      config.columns[:description].form_ui = :textarea
      config.columns[:description].options = { :cols => 100, :rows => 10 }

      config.columns[:expert_query].form_ui = :textarea
      config.columns[:expert_query].options = { :cols => 100, :rows => 10 }
       config.actions.exclude :show
      #config.actions << :sortable
      #config.sortable.column = :position
      
                       
  end
    

  def get_project_context
    if( !params[:id].nil? )
      @project = BugList.find(params[:id]).project
    end
  end


  
  
  # GET /bug_lists
  # GET /bug_lists.xml
  def index
    @bug_lists = BugList.find(:all)

    


    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @bug_lists }
    end
  end

  def before_create_save(record)
    # write out the bug_list xml file so they show up for the generators
    
    record.name = 'bug_list_' +  record.project.bug_lists.length.to_s
    
  end



  def after_create_save(record)
    ## add the internal name to be used by the generator
    ## it would be nice if this had some when read by a human, but an ID is ok

    # write out the bug_list xml file so they show up for the generators
    # this doesn't work because the record doesn't know it's project yet
    Project.find(record.project_id).publish_bug_lists
  end

  # GET /projects/1
  # GET /projects/1.xml

  def after_update_save(record)
    # write out the bug_list xml file so they show up for the generators
    record.project.publish_bug_lists
  end

  def for_project
    @project = Project.find(params[:id])
    
    #active_scaffold_config.action_links.add "new\/" + @project.id.to_s, :label => 'Add New Team'
    #{ render :active_scaffold => @projects, :constraints => {:project_id => params[:id]} }
    respond_to do |format|
      format.html 
    end
  end
  
  
=begin  
  def list
    @bug_list = BugList.find(params[:id])
    
    active_scaffold_config.label = "Project >> " + @bug_list.project.name + " >> Bug Lists"   
  
    @bug_lists = Buglist.find_all()
  
     { render :active_scaffold => @projects }
  
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @bug_lists }
    end
  end

  # GET /bug_lists/1
  # GET /bug_lists/1.xml
  def show
    @bug_list = BugList.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @bug_list }
    end
  end

  # GET /bug_lists/new
  # GET /bug_lists/new.xml
  def new
    @bug_list = BugList.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @bug_list }
    end
  end

  # GET /bug_lists/1/edit
  def edit
    @bug_list = BugList.find(params[:id])
  end

  # POST /bug_lists
  # POST /bug_lists.xml
  def create
    @bug_list = BugList.new(params[:bug_list])

    respond_to do |format|
      if @bug_list.save
        flash[:notice] = 'BugList was successfully created.'
        format.html { redirect_to(@bug_list) }
        format.xml  { render :xml => @bug_list, :status => :created, :location => @bug_list }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @bug_list.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /bug_lists/1
  # PUT /bug_lists/1.xml
  def update
    @bug_list = BugList.find(params[:id])

    respond_to do |format|
      if @bug_list.update_attributes(params[:bug_list])
        flash[:notice] = 'BugList was successfully updated.'
        format.html { redirect_to(@bug_list) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @bug_list.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /bug_lists/1
  # DELETE /bug_lists/1.xml
  def destroy
    @bug_list = BugList.find(params[:id])
    @bug_list.destroy

    respond_to do |format|
      format.html { redirect_to(bug_lists_url) }
      format.xml  { head :ok }
    end
  end
=end
end
